package com.inforich.web.controller.screenData;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.inforich.common.annotation.Log;
import com.inforich.common.core.controller.BaseController;
import com.inforich.common.core.domain.AjaxResult;
import com.inforich.common.enums.BusinessType;
import com.inforich.common.enums.ReportSourceEnum;
import com.inforich.common.utils.poi.ExcelUtil;
import com.inforich.screenData.domain.ReportProjectTransport;
import com.inforich.screenData.service.IReportProjectTransportService;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 项目运输日汇总Controller
 *
 * @author hjm
 * @date 2022-10-27
 */
@RestController
@RequestMapping("/screenData/reportProjectTransport")
public class ReportProjectTransportController extends BaseController {

  @Autowired
  private IReportProjectTransportService reportProjectTransportService;

  /**
   * 查询项目运输日汇总列表
   */
  @PreAuthorize("@ss.hasPermi('screenData:reportProjectTransport:list')")
  @GetMapping("/list")
  public Page<ReportProjectTransport> list(Page<ReportProjectTransport> page,
      ReportProjectTransport reportProjectTransport) {
    Map<String, Object> map = beanToMap(reportProjectTransport);
    reportProjectTransportService.pageReportProjectTransport(page, map);
    return page;
  }


  /**
   * 导出项目运输日汇总列表
   */
  @PreAuthorize("@ss.hasPermi('screenData:reportProjectTransport:export')")
  @Log(title = "项目运输日汇总", businessType = BusinessType.EXPORT)
  @PostMapping("/export")
  public void export(HttpServletResponse response, ReportProjectTransport reportProjectTransport) {
    Map<String, Object> map = beanToMap(reportProjectTransport);
    List<ReportProjectTransport> list = reportProjectTransportService.listReportProjectTransport(
        map);
    ExcelUtil<ReportProjectTransport> util = new ExcelUtil<ReportProjectTransport>(
        ReportProjectTransport.class);
    util.exportExcel(response, list, "项目运输日汇总数据");
  }

  /**
   * 获取项目运输日汇总详细信息
   */
  @PreAuthorize("@ss.hasPermi('screenData:reportProjectTransport:query')")
  @GetMapping(value = "/{id}")
  public AjaxResult getInfo(@PathVariable("id") Long id) {
    return AjaxResult.success(reportProjectTransportService.getById(id));
  }

  /**
   * 新增项目运输日汇总
   */
  @PreAuthorize("@ss.hasPermi('screenData:reportProjectTransport:add')")
  @Log(title = "项目运输日汇总", businessType = BusinessType.INSERT)
  @PostMapping
  public AjaxResult add(@Validated @RequestBody ReportProjectTransport reportProjectTransport) {
    if (reportProjectTransportService.checkConflict(reportProjectTransport)) {
      return AjaxResult.error("数据重复");
    }
    reportProjectTransport.setSource(ReportSourceEnum.BACK.getDbData().intValue());
    return toAjax(reportProjectTransportService.save(reportProjectTransport));
  }

  /**
   * 修改项目运输日汇总
   */
  @PreAuthorize("@ss.hasPermi('screenData:reportProjectTransport:edit')")
  @Log(title = "项目运输日汇总", businessType = BusinessType.UPDATE)
  @PutMapping
  public AjaxResult edit(@Validated @RequestBody ReportProjectTransport reportProjectTransport) {
    if (reportProjectTransportService.checkConflict(reportProjectTransport)) {
      return AjaxResult.error("数据重复");
    }
    reportProjectTransport.setSource(ReportSourceEnum.BACK.getDbData().intValue());
    return toAjax(reportProjectTransportService.updateById(reportProjectTransport));
  }

  /**
   * 删除项目运输日汇总
   */
  @PreAuthorize("@ss.hasPermi('screenData:reportProjectTransport:remove')")
  @Log(title = "项目运输日汇总", businessType = BusinessType.DELETE)
  @DeleteMapping("/{ids}")
  public AjaxResult remove(@PathVariable Long[] ids) {
    return toAjax(reportProjectTransportService.removeByIds(Arrays.asList(ids)));
  }
}
